#@head() 
#@header()
<title>融资需求管理</title>
#@aside("custser")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">客服绩效</a></li>
            </ul>
            <div class="tab-content">
              <!-- 查看承诺函 -->
			<div class="tab-pane active" id="tab_1">
				<div class="input-group margin" style="width:100%;float:left">
					<!--
					<label style="float:left;margin-top:8px;margin-left:5px;">起止时间：</label>
					<input id="createTimeStar" style="width:150px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
					<label style="float:left;margin-top:8px;">—</label>
					<input id="createTimeEnd" style="width:150px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
					-->
					<input id="name" type="text" style="width:150px;float:left;" class="form-control" placeholder="输入姓名">
					<span style="float:left;margin-left:20px;" class="input-group-btn">
					  <button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
					</span>
				</div>
				<div class="box-body">
					<table  id="example1" class="table table-striped">
						<thead>
							<tr>
								<th>客服编号</th>
								<th>客服姓名</th>
								<th>角色</th>
								<th>分组</th>
								<th>当月目标（万元）</th>
								<th>客户还款（元）</th>
								<th>客户提现（元）</th>
								<th>客户投资（元）</th>
								<th>完成进度</th>
							</tr>
						</thead>
						<tbody id="userlist">
							
						</tbody>
					</table>
					<div class="box-footer clearfix">
					  <ul class="pagination pagination-sm no-margin pull-right">
						<li id="userlist1"><a href="#">首页</a></li>
						<li id="userlist2"><a href="#">上一页</a></li>
						<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
						<li id="userlist3"><a href="#">下一页</a></li>
						<li id="userlist4"><a href="#">尾页</a></li>
					  </ul>
					</div>
				</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${workcode}</td>
		<td>${real_name}</td>
		<td>${role}</td>
		<td>${groups}组</td>
		<td>
			<input type="text" disabled style="width:100px;float:left" class="form-control" value="${target}" >
			<button style="float:left" type="button" class="changetarget">修改</button> 
			<button hidden style="float:left" type="button" agentids="${id}" class="targettrue">确认</button>
		</td>
		<td>￥${repay}</td>
		<td>￥${withdraw}</td>
		<td>￥${trade}</td>
		<td>${finish}%</td>
	</tr>
</script>
<script>
 $(document).ready(function(){
	var pageNumber = 1;
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber);
	$("#userlist5").html(pageNumber);
	$("#userlist1").click(function(){
		$("#userlist").empty();
		pageNumber = 1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
	}); 
	$("#userlist2").click(function(){
		if(pageNumber==1){
			alert("当前页是首页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist3").click(function(){
		if(pageNumber==totalPage){
			alert("当前页是尾页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber +1;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist4").click(function(){
		$("#userlist").empty();
		pageNumber = totalPage;
		userlist(pageNumber);
		$("#userlist5").html(pageNumber);
	});
	
	function userlist(pageNumber){
		$.getJSON("/merit/list?token=#(session.token??)&page="+pageNumber+"&size=12", function(userli) {
			console.log(userli);
			$.each(userli.data.agents,function(i, item){ 
				if(item.staff.target!=0){
					var finish = ((item.trade - item.repay)/(item.staff.target*100)).toFixed(2);
				}else { 
					var finish = 0;
				}
				if(item.staff.role == "agent"){
					var agent = "客服";
				}else if(item.staff.role == "agent_leader"){
					var agent = "客服组长";
				}else if(item.staff.role == "agent_manager"){
					var agent = "客服主管";
				}
				var userlist = {id:item.staff.id,withdraw:item.withdraw,groups:item.staff.groups,finish:finish,target:item.staff.target,workcode:item.staff.workcode,role:agent,real_name:item.staff.real_name,repay:item.repay,trade:item.trade};
				$("#userlistall").tmpl(userlist).appendTo('#userlist');
			});
			$(".changetarget").click(function(){
				
				$(this).prev().attr("disabled",false);
				$(this).hide();
				$(this).next().show();
				
			});
			$(".targettrue").click(function(){
				var agentid = $(this).attr("agentids");
				var thetarget = $(this).prev().prev().val();
				$.getJSON("/staff/setTarget?token=#(session.token??)&id="+agentid+"&target="+thetarget, function(changetargetinfo) {
					if(changetargetinfo.code=='success'){
						layer.msg(changetargetinfo.msg, {time: 1000, icon:1},function(){
							window.location.href="/admin/page/custser-achievement";
						});
					}else if(changetargetinfo.code=='error'){
						layer.msg(changetargetinfo.msg, {icon:2},function(){
				
						});
					}
				});
			});
			
		});	
	}
});
   
</script> 


</body>
</html>

